<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="/template/MemberItineraryTemplate.xhtml">

    <ui:define name="contentInsert">
               
        <h3>#{cartBean.customerEmail}'s cart</h3>

        
        <h:form>
            <br/>
            <br/>
            <p:dataTable value="#{cartBean.getItems()}" var="o"
                         emptyMessage="Your cart is empty"
                         onRowEditUpdate="subtotal"
                         rowEditListener="#{cartBean.updateListenAction}"
                         >

                <p:column style="width: 10px">
                    <f:facet name="header">Item ID</f:facet>
                                    #{o.item_ID}
                </p:column>

                <p:column style="width: 50px">
                    <f:facet name="header">Item Name</f:facet>
                                    #{o.item_name}
                </p:column>

                <p:column style="width: 10px">

                    <f:facet name="header">Quantity</f:facet>
                    <p:cellEditor>                        
                        <f:facet name="output">  
                            <h:outputText value="#{o.item_quantity}" />  
                        </f:facet>

                        <f:facet name="input">  
                            <p:inputText id="quantityInput" value="#{o.item_quantity}">
                                <f:validateLongRange minimum="1"/> 
                            </p:inputText>              
                            <p:message for="quantityInput"/>
                        </f:facet>


                    </p:cellEditor> 

                    <p:rowEditor /> 
                </p:column>

                <p:column style="width: 30px">
                    <f:facet name="header">Price</f:facet>
                    <h:outputText value="#{o.item_price}" >
                        <f:convertNumber type="currency" currencySymbol ="$"/>
                    </h:outputText>
                </p:column>

                <p:column style="width: 80px">
                    <f:facet name="header">Seller</f:facet>
                                    #{o.seller}
                </p:column>

                <p:column style="width: 80px">
                    <f:facet name="header">Outlet ID</f:facet>
                                    #{o.item_outletID}
                </p:column>

                <p:column style="width: 80px">
                    <f:facet name="header">Outlet Name</f:facet>
                                    #{o.item_outletName}
                </p:column>


                <p:column style="width: 50px">                    
                    <p:commandButton value="Remove" action="#{cartBean.removeFromCart(o)}" ajax="false"/>
                </p:column>
            </p:dataTable>
            
            <h5>Subtotal: </h5><h:outputText id="subtotal" value="#{cartBean.getSubtotal()}" >
                                    <f:convertNumber type="currency" currencySymbol ="$"/>
                                </h:outputText>

        </h:form>  
        
        <!--***********************************************************************************************************************-->
        
        <h:form>

                <p:commandButton value="Empty Cart" onclick="dialogue_emptyCart.show();"/> <br/>
                <p:commandButton value="Back" action="./home.xhtml?faces-redirect=true"/> 
                <br/>
                <br/>


        </h:form>
        
        
        <p:dialog header="Empty Cart" widgetVar="dialogue_emptyCart">  
            <h:outputText value="Are you sure you want to empty your cart?" /><br/>  
            <h:form>
                <p:commandButton value="Yes" action="#{cartBean.emptyCart()}" oncomplete="dialogue_emptyCart.hide();" ajax="false" update ="subtotal"/>
                <p:commandButton value="No"  oncomplete="dialogue_emptyCart.hide();" update ="subtotal"/>
            </h:form>
        </p:dialog>  
        
        
        
        
        
        
        
        <!--***********************************************************************************************************************-->
        
        <!--Paypal button-->
        <form id="id_PaypalForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" 
                  style="margin-left:auto;margin-right:auto;">  
              
                 <input type="hidden" name="cmd" value="_xclick"/>  
                 <input type="hidden" name="business" value="#{returnURLMB.tCubePayPalEmail}"/>  
                 <input type="hidden" name="item_name"   value="Purchase Order"/>  
                 <input type="hidden" name="item_number" value="0"/>  
                 <input type="hidden" name="amount" value="#{cartBean.getSubtotal()}"/>  
                 <input type="hidden" name="tax" value="0"/>  
                 <input type="hidden" name="quantity" value="1"/>  
                 <input type="hidden" name="no_note" value="1"/>  
                 <input type="hidden" name="currency_code" value="SGD"/> 
                 <input type="hidden" name="return" value="#{returnURLMB.getReturnURL_shoppingCartCheckout()}"/> 
                
                <input type="image" name="submit" border="0"
                        src="https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif"  
                        alt="PayPal - The safer, easier way to pay online"
                />  
        </form> 
        <!--End Paypal button-->

        
        
        

    </ui:define>
</ui:composition>

